package com.ggh.jinjilive.utils.im;

import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.mobile.live.im.CustomMessage;
import com.ggh.jinjilive.ui.live.adapter.TVLiveMessageAdapter;
import com.ggh.jinjilive.utils.GlideEngine;

public class LiveMessageUtils {

    private static LiveMessageUtils instance = null;
    //获取单例
    public static LiveMessageUtils getInstance() {
        if (null == instance) {
            synchronized (GlideEngine.class) {
                if (null == instance) {
                    instance = new LiveMessageUtils();
                }
            }
        }
        return instance;
    }


    /**
     * 添加消息
     * @param customMessage
     */
    public void robotMessage(CustomMessage customMessage, TVLiveMessageAdapter tvLiveMessageAdapter, RecyclerView tvMessageList){
        if(null != customMessage){
            tvLiveMessageAdapter.setCustomMessage(customMessage);
            tvMessageList.post(new Runnable() {
                @Override
                public void run() {
                    tvMessageList.scrollToPosition(tvLiveMessageAdapter.getCustomMessageList().size() - 1);
                }
            });
        }
    }
}
